// 资产库可用资产信息
var purchaseProductDatas = new Array();

$$scope.submmitData = {};
$$scope.submmitData.purchaseStepEntity = {
    "processInstanceId": $CertusJsonAjax.getProInstanceId(),
    "stepInstanceId": $CertusJsonAjax.getStepInstanceId(),
}
$$scope.select = {};
// 采购记录
var proc1Columns = [
    {
        id: 'commodityCateName',
        title: '类目',
        width: 73,
        type: 'string',
        columnClass: 'text-center',
    }, {
        id: 'commodityClassName',
        title: '类别',
        width: 73,
        type: 'string',
        columnClass: 'text-center',
    }, {
        id: 'name',
        title: '名称',
        width: 73,
        type: 'string',
        columnClass: 'text-center',
    }, {
        id: 'descAndSpec',
        title: '品名及规格',
        width: 200,
        type: 'string',
        columnClass: 'text-left',
    }, {
        id: 'quantity',
        title: '数量',
        width: 100,
        type: 'string',
        columnClass: 'text-center',
    }, {
        id: 'estimatedAmount',
        title: '预计金额',
        width: 150,
        type: 'string',
        columnClass: 'text-center',
        resolution: function (value, record, column, grid, dataNo, columnNo) {
            var content = '￥' + value + '元';
            return content;
          }
    }, {
        id: 'remark',
        title: '备注',
        type: 'string',
        columnClass: 'text-left',
    }];
var productSelectDatagrid = null;
var nowBiCode = '';
function openModal(commodityCateCode, commodityClassCode, biCodes) {

    if (productSelectDatagrid == null) {
        productSelectDatagrid = $CertusJsonAjax.dataInit("findAssetsList", null, lidColumns, 'lidContainer', 'lidToolBarContainer',5, [10]);
    }
    nowBiCode = biCodes
    $$scope.select.assetBigClass = commodityCateCode;
    $$scope.select.productType = commodityClassCode;
    productSelectDatagrid.parameters = {code: 9, param: commodityClassCode};
    productSelectDatagrid.refresh(true);
    $$scope.$apply();
    $("#myModal").modal('show');
}
// 资产库借货记录
var library1Columns = [
//     {
//     id: 'number',
//     title: '序号',
//     width: 45,
//     type: 'string',
//     columnClass: 'text-center',
// },
 {
    id: 'list',
    title: '资产类目',
    width: 73,
    type: 'string',
    columnClass: 'text-center',
}, {
    id: 'asset_style2',
    title: '资产类别',
    width: 73,
    type: 'string',
    columnClass: 'text-center',
}, {
    id: 'asset_id',
    title: '资产编号',
    width: 170,
    type: 'string',
    columnClass: 'text-center',
}, {
    id: 'comments',
    title: '资产描述',
    type: 'string',
    columnClass: 'text-left',
}, {
    id: 'asset_status',
    title: '状态',
    width: 75,
    type: 'string',
    columnClass: 'text-center',
}, {
    id: 'create_user_id',
    title: '归属人',
    width: 75,
    type: 'string',
    columnClass: 'text-center',
}, {
    id: 'pro_name',
    title: '归属项目',
    width: 75,
    type: 'string',
    columnClass: 'text-center',
}, {
    id: 'city_location',
    title: '放置地',
    width: 75,
    type: 'string',
    columnClass: 'text-center',
}];


var lidColumns = [{
    id: 'asset_id',
    title: '资产编号',
    width: 170,
    type: 'string',
    columnClass: 'text-center',
}, {
    id: 'city_location',
    title: '放置地',
    width: 73,
    type: 'string',
    columnClass: 'text-center',
}, {
    id: 'comments',
    title: '资产描述',
    type: 'string',
    columnClass: 'text-left',
}
];

var belowGrid;
var aboveGrid;
var brCode;
$CertusJsonAjax.ajax("purchaseBaseInfo", {
    "processInstanceId": $CertusJsonAjax.getProInstanceId(),
    "stepInstanceId": $CertusJsonAjax.getStepInstanceId()
}, function (res) {
    if (res.data) {

        $$scope.headerMap = res.data.headerMap;
        $$scope.processs = res.data.processs;
        brCode = res.data.headerMap.brCode;
        $$scope.submmitData.purchaseStepEntity.buyingRequisitionCode = res.data.headerMap.brCode;
        $$scope.submmitData.purchaseStepEntity.projId = res.data.headerMap.projId;
        var priceOption1 = {
            lang: 'zh-cn',
            ajaxLoad: false,
            extraWidth: 20,
            // loadURL:'url',
            exportFileName: '采购单条目信息',
            datas: res.data.buyings,
            columns: proc1Columns,
            gridContainer: 'proc3Container',
        };
        aboveGrid = $.fn.dlshouwen.grid.init(priceOption1);
        aboveGrid.load();

        var priceOption2 = {
            lang: 'zh-cn',
            ajaxLoad: false,
            extraWidth: 20,
            // loadURL:'url',
            exportFileName: '资产库申请清单',
            datas: res.data.inventors,
            columns: library1Columns,
            gridContainer: 'library3Container'
        };
        belowGrid = $.fn.dlshouwen.grid.init(priceOption2);
        belowGrid.load();

    }
})


$$scope.approvalApplyApproveProjManager = function () {
    //添加
    if (certusValidateNotnull()) {
        $$scope.submmitData.purchaseStepEntity.findWhoType = "C";
        $CertusJsonAjax.ajax("ordinaryApproval", $$scope.submmitData.purchaseStepEntity, function (res) {
            if (res.data) {
                if ("success" == res.data) {
                    findBacklogPerson($CertusFormAjax, $CertusJsonAjax.getStepInstanceId());
                    window.history.back();
                    return;
                }
                layer.msg(res.data);
            }
        })
    }
}

$$scope.getsssbbb = function(bb){
    ;
    //starting denied sentback others completed
    if(bb == "starting"){
        return "正在进行中";
    }else if(bb == "denied"){
        return "否决";
    }else if(bb == "sentback"){
        return "被退";
    }else if(bb == "others"){
        return "关闭";
    }else if(bb == "completed"){
         return "完成";    }else if(bb == "terminated"){        return "终结";    }    else if(bb == "cancelled"){        return "通过";}
    return "待办";
}
//退回至 起草人
$$scope.comebackToStart = function () {
    if (certusValidateNotnull()) {
        $CertusJsonAjax.ajax("vetoPurchaseInitiator", {
            "processInstanceId": $CertusJsonAjax.getProInstanceId(),
            "stepInstanceId": $CertusJsonAjax.getStepInstanceId(),
            "opinionMsg":$$scope.submmitData.purchaseStepEntity.opinionMsg
        },function(res){
            if(res.data){
                if(res.data == "success"){
                    window.history.back();
                }
                layer.msg(res.data);
            }
        })
    }
}